package io.geekidea.springbootplus.system.controller;

import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.system.entity.SysProductAttribute;
import io.geekidea.springbootplus.system.service.SysProductAttributeService;
import io.geekidea.springbootplus.system.vo.SysProductAttributeQueryVo;
import io.geekidea.springbootplus.system.vo.SysProductQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@Slf4j
@RestController
@RequestMapping("/sysAttr")
@Module("system")
@Api(value = "商品属性信息API", tags = {"商品属性信息"})
public class SysProductAttributeController extends BaseController {

    @Resource
    private SysProductAttributeService sysProductAttributeService;



    @PostMapping("/add")
    @OperationLog(name = "添加商品属性信息", type = OperationLogType.ADD)
    @ApiOperation(value = "添加商品属性信息", response = ApiResult.class)
    public ApiResult<Boolean> addSysProductAttribute(@Validated(Add.class) @RequestBody SysProductAttribute sysProductAttribute) throws Exception {
        boolean flag = sysProductAttributeService.saveSysProductAttribute(sysProductAttribute);
        return ApiResult.result(flag);
    }


    /**
     * 修改商品shux信息
     */
    @PostMapping("/update")
    @OperationLog(name = "修改商品属性信息", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改商品属性信息", response = ApiResult.class)
    public ApiResult<Boolean> updateSysProductAttribute(@Validated(Update.class) @RequestBody SysProductAttribute sysProductAttribute) throws Exception {
        boolean flag = sysProductAttributeService.updateSysProductAttribute(sysProductAttribute);
        return ApiResult.result(flag);
    }

    /**
     * 查询商品属性信息
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "查询商品信息详情", type = OperationLogType.INFO)
    @ApiOperation(value = "查询商品信息详情", notes = "")
    public ApiResult<SysProductAttribute> getSysProductAttribute(@PathVariable("id") Integer id) throws Exception {
        SysProductAttribute sysProductAttribute = sysProductAttributeService.getSysProductAttributeById(id);
        return ApiResult.ok(sysProductAttribute);
    }


    /**
     * 删除商品属性信息
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除商品信息详情", type = OperationLogType.INFO)
    @ApiOperation(value = "删除商品信息详情", notes = "")
    public ApiResult<Boolean> deleteSysProductAttribute(@PathVariable("id") Integer id) throws Exception {
        boolean flag = sysProductAttributeService.deleteSysProductAttribute(id);
        return ApiResult.ok(flag);
    }


    @PostMapping("/getPageList")
    @OperationLog(name = "商品信息分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "商品信息分页列表", response = SysProductQueryVo.class)
    public ApiResult<Paging<SysProductAttributeQueryVo>> getSysProductAttributePageList() throws Exception {
        Paging<SysProductAttributeQueryVo> paging = sysProductAttributeService.getSysProductAttributePageList();
        return ApiResult.ok(paging);

    }


}
